<!--
 * @Author: 敬华丰 2637844016@qq.com
 * @Date: 2023-04-27 11:03:37
 * @LastEditors: 敬华丰 2637844016@qq.com
 * @LastEditTime: 2023-05-05 09:36:35
 * @FilePath: \imedia_crm-branch_v5.0.1_0518\src\allocation\resourceManage\vehicle-info\components\c-vehicle-form.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <el-dialog :title="`${ruleForm.id?'编辑':'新增'}品牌${ruleForm.id?'信息':''}`" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="auto">
            <el-form-item label="车辆品牌" prop="brand">
                <el-input v-model="ruleForm.brand" placeholder="请输入车辆品牌"></el-input>
            </el-form-item>

            <el-form-item prop="icon" label="品牌Logo">
                <c-upload @change="$refs.ruleForm.validateField('icon')" :limit="1" v-model="ruleForm.icon" listType="text" />
            </el-form-item>

        </el-form>
        <span slot="footer">
            <el-button :loading="loading" @click="handleClose">取 消</el-button>
            <el-button :loading="loading" type="primary" @click="handleSubmit">确 定</el-button>
        </span>
    </el-dialog>
</template>
<script>
export default {
    data () {
        return {
            dialogVisible: false,
            loading: false,
            ruleForm: {
                brand: "",
                icon: ""
            },
            rules: {
                brand: [{ required: true, message: "请输入车辆品牌", trigger: "blur" }],
                icon: [{ required: true, message: "请上传品牌Logo", trigger: "blur" }],
            },
        };
    },
    methods: {
        handleSubmit () {
            this.$refs.ruleForm.validate((valid) => {
                if (valid) {
                    this.$confirm("是否确认此操作?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }).then(() => {
                        // this.ruleForm.icon = this.ruleForm.icon[0]
                        const data = JSON.parse(JSON.stringify(this.ruleForm));
                        const url = `/CarBrand/${data.id ? "update" : "insert"}`;
                        this.loading = true;
                        this.$post({ url, data }).then(
                            (res) => {
                                this.$message.success("操作成功");
                                this.handleClose();
                                this.loading = false;
                                this.$parent.$parent.tableList();
                            },
                            () => {
                                this.loading = false;
                            }
                        );
                    });
                }
            });
        },
        handleOpen (item) {
            if (item) {
                this.ruleForm = item
            }
            this.dialogVisible = true;
        },
        handleClose () {
            this.$refs.ruleForm.resetFields();
            this.ruleForm = {};
            this.dialogVisible = false;
        },
    },
};
</script>
